package cn.lichenfei.fxui.controls;

import cn.lichenfei.fxui.common.SimpleControl;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;

public class CFForm extends GridPane {

    public CFForm() {
        setHgap(20);
        setVgap(20);
        setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
    }

    public void add(String text, Node node, int rowIndex) {
        add(text, node, rowIndex, HPos.RIGHT, VPos.TOP);
    }

    /**
     * 将多个node添加到FlowPane
     */
    public void addNodes(String text, int rowIndex, Node... nodes) {
        FlowPane flowPane = new FlowPane(nodes);
        flowPane.hgapProperty().bind(hgapProperty());
        flowPane.vgapProperty().bind(vgapProperty().divide(2));
        add(text, flowPane, rowIndex, HPos.RIGHT, VPos.TOP);
    }

    public void add(String text, Node node, int rowIndex, HPos textHPos, VPos textVPos) {
        Label label = SimpleControl.getLabel(text);
        label.setWrapText(false);
        label.setPrefHeight(32);
        label.setMinSize(USE_PREF_SIZE, USE_PREF_SIZE);
        GridPane.setHalignment(label, textHPos);
        GridPane.setValignment(label, textVPos);
        add(label, 0, rowIndex);
        add(node, 1, rowIndex);
    }

}
